﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V5_DAL;
using System.Data;
using V5_Model;
using V5_Common;

namespace V5_BLL
{
    public class BLLUserToArea
    {
        DALUserToArea dal = new DALUserToArea();
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ModelUserToArea model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(ModelUserToArea model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int id)
        {

            dal.Delete(id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelUserToArea GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public ModelUserToArea GetModelByCache(int id)
        {

            string CacheKey = "ModelUserToAreaModel-" + id;
            object objModel = DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("ModelCache");
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (ModelUserToArea)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelUserToArea> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelUserToArea> DataTableToList(DataTable dt)
        {
            List<ModelUserToArea> modelList = new List<ModelUserToArea>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ModelUserToArea model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ModelUserToArea();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    model.tousername = dt.Rows[n]["tousername"].ToString();
                    model.touserareapro = dt.Rows[n]["touserareapro"].ToString();
                    model.touserareacity = dt.Rows[n]["touserareacity"].ToString();
                    model.touserareacity2 = dt.Rows[n]["touserareacity2"].ToString();
                    model.touserurl = dt.Rows[n]["touserurl"].ToString();
                    model.topostnum = dt.Rows[n]["topostnum"].ToString();
                    model.touserphone = dt.Rows[n]["touserphone"].ToString();
                    model.tousertelephone = dt.Rows[n]["tousertelephone"].ToString();
                    if (dt.Rows[n]["adddatetime"].ToString() != "")
                    {
                        model.adddatetime = DateTime.Parse(dt.Rows[n]["adddatetime"].ToString());
                    }
                    if (dt.Rows[n]["userid"].ToString() != "")
                    {
                        model.userid = int.Parse(dt.Rows[n]["userid"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        #endregion  成员方法
        #region 51aspx下载
        #endregion
    }
}
